package com.hongshan.wallet.bean

import com.hongshan.wallet.MyApplication

data class UserBean(
    val account_id: Int = 0,
    val mobile: String = "",
    val token: String = "",
    val username: String = ""
) {
    fun save() {
        MyApplication.sp.edit().apply {
            putInt("account_id", account_id)
            putString("mobile", mobile)
            putString("token", token)
            putString("username", username)
        }.apply()
    }

    fun clean(){
        MyApplication.sp.edit().apply {
            putInt("account_id", 0)
            putString("mobile", "")
            putString("token", "")
            putString("username", "")
        }.apply()
    }

    fun isEmpty() = token.isEmpty() || username.isEmpty()

    companion object {
        @Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
        fun load(): UserBean {
            return UserBean(
                MyApplication.sp.getInt("account_id", 0),
                MyApplication.sp.getString("mobile", ""),
                MyApplication.sp.getString("token", ""),
                MyApplication.sp.getString("username", "")
            )
        }
    }
}